﻿using System;
using System.Data;
using System.Collections;
using CE.Database;

/// <summary>
/// Summary description for ViriyahCarMoreDetailDB
/// </summary>
namespace CE.CarInsurance
{
    public class ViriyahCarMoreDetailDB
    {
        public ViriyahCarMoreDetailDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(ViriyahCarMoreDetail viriyahcarmoredetail)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocCarMoreDetailInsertUpdateSingleItemViriyah";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@CECarMoreDetailId", viriyahcarmoredetail.CECarMoreDetailId);
            _sPara.Add("@CECarId", viriyahcarmoredetail.CECarId);
            _sPara.Add("@ProviderCompanyId", viriyahcarmoredetail.ProviderCompanyId);
            _sPara.Add("@AnnualPremium", viriyahcarmoredetail.AnnualPremium);
            _sPara.Add("@TermPremium", viriyahcarmoredetail.TermPremium);
            _sPara.Add("@Name", viriyahcarmoredetail.Name);
            _sPara.Add("@IdentificationNo", viriyahcarmoredetail.IdentificationNo);
            _sPara.Add("@Occupation", viriyahcarmoredetail.Occupation);
            _sPara.Add("@ContactNo", viriyahcarmoredetail.ContactNo);
            _sPara.Add("@OfficePhoneNo", viriyahcarmoredetail.OfficePhoneNo);
            _sPara.Add("@BeneficiaryName", viriyahcarmoredetail.BeneficiaryName);

            _sPara.Add("@CarPlate", viriyahcarmoredetail.CarPlate);
            _sPara.Add("@CarPlateProvince", viriyahcarmoredetail.CarPlateProvince);
            _sPara.Add("@PresentAddress", viriyahcarmoredetail.PresentAddress);
            _sPara.Add("@SubDistrict", viriyahcarmoredetail.SubDistrict);
            _sPara.Add("@District", viriyahcarmoredetail.District);
            _sPara.Add("@Province", viriyahcarmoredetail.Province);
            _sPara.Add("@PostalCode", viriyahcarmoredetail.PostalCode);
            _sPara.Add("@IsMailingAddressDiff", viriyahcarmoredetail.IsMailingAddressDiff);
            _sPara.Add("@MailingAddress", viriyahcarmoredetail.MailingAddress);
            _sPara.Add("@MailingSubDistrict", viriyahcarmoredetail.MailingSubDistrict);
            _sPara.Add("@MailingDistrict", viriyahcarmoredetail.MailingDistrict);
            _sPara.Add("@MailingProvince", viriyahcarmoredetail.MailingProvince);
            _sPara.Add("@MailingPostalCode", viriyahcarmoredetail.MailingPostalCode);
            _sPara.Add("@EngineNumber", viriyahcarmoredetail.EngineNumber);
            _sPara.Add("@ChassisNumber", viriyahcarmoredetail.ChassisNumber);
            _sPara.Add("@IsCTPL", viriyahcarmoredetail.IsCTPL);
            _sPara.Add("@CTPL", viriyahcarmoredetail.CTPL);
            _sPara.Add("@PaymentOption", viriyahcarmoredetail.PaymentOption);
            _sPara.Add("@PaymentType", viriyahcarmoredetail.PaymentType);
            _sPara.Add("@PaymentBank", viriyahcarmoredetail.PaymentBank);

            _sPara.Add("@OrderRefNoId", viriyahcarmoredetail.OrderRefNoId);
            _sPara.Add("@OrderRefNo", viriyahcarmoredetail.OrderRefNo);
            _sPara.Add("@PaymentStatus", viriyahcarmoredetail.PaymentStatus);

            _sPara.Add("@QuoteRefNo", viriyahcarmoredetail.QuoteRefNo);
            _sPara.Add("@RefCEUserId", viriyahcarmoredetail.RefCEUserId);
            _sPara.Add("@ViewedDetailId", viriyahcarmoredetail.ViewedDetailId);
            _sPara.Add("@CarResultId", viriyahcarmoredetail.CarResultId);
            _sPara.Add("@Ninfo4", viriyahcarmoredetail.Ninfo4); // For AgentId
            _sPara.Add("@Ninfo5", viriyahcarmoredetail.Ninfo5); // Submission
            _sPara.Add("@Status", viriyahcarmoredetail.Status);
            _sPara.Add("@Ninfo1", viriyahcarmoredetail.Ninfo1);
            _sPara.Add("@Info1", viriyahcarmoredetail.Info1);
            _sPara.Add("@Info2", viriyahcarmoredetail.Info2);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public ViriyahCarMoreDetail GetCarMoreDetail(Int64 CarId, Int64 CEUserId)
        {
            ViriyahCarMoreDetail _viriyahcarmoredetail = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocCarMoreDetailSelectSingleItemViriyah";

            SortedList _spara = new SortedList();
            _spara.Add("@CECarID", CarId);
            _spara.Add("@RefCEUserId", CEUserId);

            DataTable _dt = _db.GetDataTableBySP(_spName, _spara);
            if (_dt != null)
            {
                if (_dt.Rows.Count > 0)
                {
                    _viriyahcarmoredetail = new ViriyahCarMoreDetail();
                    _viriyahcarmoredetail = FillDataRecord(_dt);
                }
            }
            return _viriyahcarmoredetail;
        }

        private ViriyahCarMoreDetail FillDataRecord(DataTable myDataTable)
        {
            ViriyahCarMoreDetail myCarMoreDetail = new ViriyahCarMoreDetail();
            myCarMoreDetail.CECarMoreDetailId = Convert.ToInt64(myDataTable.Rows[0]["CECarMoreDetailId"].ToString());
            myCarMoreDetail.CECarId = Convert.ToInt64(myDataTable.Rows[0]["CECarId"].ToString());
            myCarMoreDetail.ProviderCompanyId = Convert.ToInt64(myDataTable.Rows[0]["ProviderCompanyId"].ToString());
            myCarMoreDetail.AnnualPremium = Convert.ToSingle(myDataTable.Rows[0]["AnnualPremium"].ToString());
            myCarMoreDetail.TermPremium = Convert.ToSingle(myDataTable.Rows[0]["TermPremium"].ToString());
            myCarMoreDetail.Name = myDataTable.Rows[0]["Name"].ToString();
            if (myDataTable.Rows[0]["IdentificationNo"] != null)
            {
                myCarMoreDetail.IdentificationNo = myDataTable.Rows[0]["IdentificationNo"].ToString();
            }
            myCarMoreDetail.Occupation = myDataTable.Rows[0]["Occupation"].ToString();
            myCarMoreDetail.ContactNo = myDataTable.Rows[0]["ContactNo"].ToString();
            myCarMoreDetail.OfficePhoneNo = myDataTable.Rows[0]["OfficePhoneNo"].ToString();
            myCarMoreDetail.BeneficiaryName = myDataTable.Rows[0]["BeneficiaryName"].ToString();

            myCarMoreDetail.CarPlate = myDataTable.Rows[0]["CarPlate"].ToString();
            myCarMoreDetail.CarPlateProvince = myDataTable.Rows[0]["CarPlateProvince"].ToString();
            myCarMoreDetail.PresentAddress = myDataTable.Rows[0]["PresentAddress"].ToString();
            myCarMoreDetail.SubDistrict = myDataTable.Rows[0]["SubDistrict"].ToString();
            myCarMoreDetail.District = myDataTable.Rows[0]["District"].ToString();
            myCarMoreDetail.Province = myDataTable.Rows[0]["Province"].ToString();
            myCarMoreDetail.PostalCode = myDataTable.Rows[0]["PostalCode"].ToString();
            myCarMoreDetail.IsMailingAddressDiff = Convert.ToBoolean(myDataTable.Rows[0]["IsMailingAddressDiff"].ToString());
            myCarMoreDetail.MailingAddress = myDataTable.Rows[0]["MailingAddress"].ToString();
            myCarMoreDetail.MailingSubDistrict = myDataTable.Rows[0]["MailingSubDistrict"].ToString();
            myCarMoreDetail.MailingDistrict = myDataTable.Rows[0]["MailingDistrict"].ToString();
            myCarMoreDetail.MailingProvince = myDataTable.Rows[0]["MailingProvince"].ToString();
            myCarMoreDetail.MailingPostalCode = myDataTable.Rows[0]["MailingPostalCode"].ToString();
            myCarMoreDetail.EngineNumber = myDataTable.Rows[0]["EngineNumber"].ToString();
            myCarMoreDetail.ChassisNumber = myDataTable.Rows[0]["ChassisNumber"].ToString();
            myCarMoreDetail.IsCTPL = Convert.ToBoolean(myDataTable.Rows[0]["IsCTPL"].ToString());
            myCarMoreDetail.CTPL = Convert.ToSingle(myDataTable.Rows[0]["CTPL"].ToString());


            myCarMoreDetail.PaymentOption = myDataTable.Rows[0]["PaymentOption"].ToString();
            myCarMoreDetail.PaymentType = myDataTable.Rows[0]["PaymentType"].ToString();
            myCarMoreDetail.PaymentBank = myDataTable.Rows[0]["PaymentBank"].ToString();
            myCarMoreDetail.QuoteRefNo = myDataTable.Rows[0]["QuoteRefNo"].ToString();
            myCarMoreDetail.RefCEUserId = Convert.ToInt64(myDataTable.Rows[0]["RefCEUserId"].ToString());
            myCarMoreDetail.CarResultId = Convert.ToInt64(myDataTable.Rows[0]["CarResultId"].ToString());
            if (myDataTable.Rows[0]["Ninfo4"] != null)
            {
                myCarMoreDetail.Ninfo4 = Convert.ToInt64(myDataTable.Rows[0]["Ninfo4"].ToString());
            }
            if (myDataTable.Rows[0]["Ninfo5"] != null)
            {
                myCarMoreDetail.Ninfo5 = Convert.ToInt32(myDataTable.Rows[0]["Ninfo5"].ToString());
            }
            myCarMoreDetail.Status = Convert.ToBoolean(myDataTable.Rows[0]["Status"].ToString());
            //myCarMoreDetail.Ninfo1 = Convert.ToInt64(myDataTable.Rows[0]["Ninfo1"].ToString());


            return myCarMoreDetail;
        }

        public DataSet GetCarPolicyDetails(Int64 CarId, Int64 CEId, Int64 CXCoverTypeId, Int64 ProviderCompanyId)
        {
            DataSet _result = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocCarInsuranceTHSelectedPlanSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@CECarId", CarId);
            _spara.Add("@RefCEUserId", CEId);
            _spara.Add("@CITempResultId", CXCoverTypeId);
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);


            using (DataSet _ds = _db.GetDataSet(_spName, _spara))
            {
                if (_ds != null && _ds.Tables.Count > 0 && _ds.Tables[0].Rows.Count > 0)
                {
                    _result = _ds;
                }
            }
            return _result;
        }

        public Int64 CheckConfirmStatus(Int64 CarId, string ResultType)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocCheckUserConfirmStatus";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@CECarId", CarId);
            _sPara.Add("@ResultType", ResultType);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

    }
}